/*jslint vars: true, forin:true, sloppy: true*/
/*global angular, probe*/
probe.controller("wait", function ($scope, $element, $filter, ocDialog) {
	var DI = ocDialog.queryDI($element);
	var data = DI.share;

	$scope.delay = 500;//default
	if (data.edit) {
		$scope.delay = data.ins[data.index].BODY.delay;
	}

	$scope.ok = function () {
		//use filter to generate abstraction on the result
		var newIns = $filter("translateIns")([{
			LINE: -1,
			TYPE: 0,
			BODY: {
				delay: parseInt($scope.delay, 0)
			}
		}])[0];

		if (data.edit) {
			data.ins[data.index] = newIns;
		} else {
			if (data.index > -1) {
				data.ins.splice(data.index, 0, newIns);
			}
			//nothing is selected, append instruction at the end
			else {
				data.ins.push(newIns);
			}
		}
		///have to manually refresh
		data.refresh();

		DI.closeDialog();
	};
});